<?php
/**
 * Created by PhpStorm.
 * User: Ason
 * Date: 15-6-29
 * Time: 上午9:31
 */
?>
<div class="modal-dialog modal-lg">
	<div class="modal-content">

		<div class="modal-header bordered-bottom-3 bordered-orange">
			<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
					class="sr-only">Close</span></button>
			<h4 class="modal-title"><span class="glyphicon glyphicon-pencil"></span>编辑用户组信息</h4>
		</div>
		<div class="modal-body">
			<!--错误提示 BEGIN-->
			<div id="edit_alert" class="alert text-center" style="display:none;"></div>
			<!--错误提示 END-->
			<form id="edit_group" method="post">
				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">用户组名</label>

					<div class="col-md-10">
						<div class="form-group">
							<input type="text" class="form-control" name="group_name" id="group_name" value="<?=$group_info[ 'name' ];?>">
						</div>
					</div>
				</div>
				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">备注</label>

					<div class="col-md-10">
						<div class="form-group">
							<input type="text" class="form-control" name="group_remark" id="group_remark" value="<?=$group_info[ 'remark' ];?>">
						</div>
					</div>
				</div>
				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">权限</label>

					<div class="col-md-10">
						<div class="form-group">
							<div class="checkbox">
								<?php foreach( $all_menu as $m ):?>
								<label>
									<input type="checkbox" name="group_right[]" value="<?=$m[ 'id' ];?>" <?php if( in_array($m['id'], $permit )) echo 'checked'?>>
									<span class="text"><?=$m[ 'name' ];?></span>
								</label>
									<?php
									if( $m[ 'sub' ] ):
									?>
									<br />
									<?php
										foreach( $m[ 'sub' ] as $sub_m ):
									?>
									
									<label>
										<input type="checkbox" name="group_right[][]" value="<?=$sub_m[ 'id' ];?>" <?php if( in_array($sub_m['id'], $permit )) echo 'checked'?>>
										<span class="text"><?=$sub_m[ 'name' ];?></span>
									</label>
									<?php
										endforeach;
									endif;
									?>
								<hr />
								<?php endforeach; ?>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>
		<div class="modal-footer">
			<div class="form-group text-right">
				<button class="btn btn-success" id="save">确认修改</button>&nbsp;&nbsp;&nbsp;&nbsp;
				<button class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<script>
	
	$("#save").click(function(){
		$.ajax({
			type:"POST",
			url:"<?=site_url('user/do_edit_group/'. $group_info[ 'id' ] );?>",
			data:$('#edit_group').serialize(),
			success:function( json ){
				$( '#edit_alert' ).removeClass( 'alert-danger show').text('');
				data = eval( '(' + json + ')' );
				if( data.status == 'error' ){
					$('#edit_alert' ).addClass('alert-danger show').text( data.error );
				}else{
					$('#edit_alert' ).addClass('alert-success show').text( data.error );
					setInterval( function(){
						window.location.reload();
					}, 2000);
				}
			}
		})
	});
</script>